function printresults(){
    //$("#condition_method_container").hide();
    //$("#medium_method_container").hide();
    window.print();
}

function ccost(){
    var rate = $("#machinerate").val();
    var hours = $("#machinehours").val();
    var addcost = $("#addcost").val();
    $("#costtotal").val(parseFloat(rate) * parseFloat(hours) + parseFloat(addcost));
}

function checkpw(){
  /*new Messi('Are you sure you want to submit?', {title: 'Buttons', buttons: [{id: 0, label: 'Yes', val: 'Y'}, {id: 1, label: 'No', val: 'N'}], callback: function(val) { 
      //alert('Your selection: ' + val); 
	if (val == 'Y')
	    save_results()
    }});
*/
}
function populate_results(results, jobid){
  if (results != null && results["operator"] != null){
   	/*
	{"machinehours": 9.5, "additionalf": "", "costtotal": 319.75, "machinerate": 32.5, "costnotes": "ohh 0jflkl", "filenotes": "lala for me", "addf": "hips_association_annotation.tsv", "results_date": "22/3/2014", "operator": "cjaeger@uni.lu", "addcost": 11.0, "statf": "hesc_association_annotation.tsv"	
	$("#rawf").val("");
	        $("#statf").val("");
		        $("#additionalf").val("");
	*/
	if (results["operator"] != "")
	    $("#operator").val(results["operator"]);
	if (results["machinerate"] != "")
	    $("#machinerate").val(results["machinerate"]);
	$("#machinehours").val(results["machinehours"]);
	$("#addcost").val(results["addcost"]);
	$("#costnotes").val(results["costnotes"]);
	$("#costtotal").val(results["costtotal"]);
	$("#filenotes").val(results["filenotes"]);
	$("#methodnotes").val(results["methodnotes"]);
	if (results["results_date"] != "")
	    $("#results_date").val(results["results_date"]);
	var rawf = results["rawf"];
	if (rawf != null && rawf != ""){
	    var rawfl = "results/" + jobid + '/' + rawf;
	    $("#rawhtml").html('<a href="' + rawfl + '">Saved: ' + rawf + '</a>');  
	}
	var statf = results["statf"];
        if (statf != null && statf != ""){
            var statfl = "results/" + jobid + '/' + statf;
            $("#stathtml").html('<a href="' + statfl + '">Saved:' + statf + '</a>');
        }
	var additionalf = results["additionalf"];
        if (additionalf != null && additionalf != ""){
            var additionalfl = "results/" + jobid + '/' + additionalf;
            $("#additionalhtml").html('<a href="' + additionalfl + '">Saved:' + additionalf + '</a>');
        }
    }
}
//Callback handler for form submit event
function save_results(){
  $("#resultsButton").prop("disabled",true);
  $("#resultsmsg").html("Working ... <img src='images/demo_wait.gif' />");
  $("#resultsform").submit(function(e)
  {
 
    var formObj = $(this);
    var formURL = "/cgi-bin/gcmsjob/save_results.cgi";
    var formData = new FormData(this);
    $.ajax({
        url: formURL,
    type: 'POST',
        data:  formData,
    mimeType:"multipart/form-data",
    contentType: false,
        cache: false,
        processData:false,
    success: function(data, textStatus, jqXHR)
    {
	$("#resultsButton").prop("disabled",false);
	$("#resultsmsg").html("<font color='red'>Thanks, form saved and email sent</font>");
   	new Messi('Results saved', {titleClass:'success',title: 'Success', autoclose: 1500});
    },
     error: function(jqXHR, textStatus, errorThrown) 
     {
        alert("oops - bad transaction");
     }          
    });
    e.preventDefault(); //Prevent Default action. 
    //e.unbind();
	}); 
}
